'''
Created on Nov 19, 2010

@author: namikata
'''

from gameobjects.vector2 import Vector2
from game.base.GameEntity import GameEntity, KMOV_DIRECTION, rotate_at_point
from game.effect.EffectList import Effect_Trail

class GBullet(GameEntity):
    '''
    classdocs
    '''

    def __init__(self,objclass, objsclass, data, parent):
        '''
        Constructor
        '''
        GameEntity.__init__(self, parent.world, data.id, parent.world.resources.dic[data.image], objclass, objsclass)
        
        self.data = data
        self.parent = parent
        self.sprite.position = Vector2(*parent.sprite.position)
        self.speed = data.speed
        self.max_speed = 150.
        self.movement_type = KMOV_DIRECTION
        self.cursor = None
        self.sprite.scale = data.scale

        self.sprite.position += data.position_offset
        self.sprite.position = rotate_at_point(self.sprite.position, parent.sprite.position, -parent.sprite.rotation)
        
        self.direction = Vector2(*parent.cursor.sprite.position) + data.position_offset
        self.direction = rotate_at_point(self.direction, parent.cursor.sprite.position, -parent.sprite.rotation + data.angle_offset)
        self.direction = self.direction - self.sprite.position
                        
    def update(self,elapsed, keyboard, mouse):       
        GameEntity.update(self, elapsed)
        if not self.parent.world.is_inside_bounds(self.sprite.position):
            self.destroy = True